// 自我测评
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="测评名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入测评名称"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="测评状态" prop="measureStatus">
        <el-select
          v-model="queryParams.measureStatus"
          placeholder="请选择测评状态"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in dict.type.measure_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="测评日期">
        <el-date-picker
          v-model="dateRange1"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="scaleList">
      <el-table-column type="selection" width="50" align="center" />
      <el-table-column label="测评名称" align="center" key="name" prop="name" />

      <el-table-column
        label="量表类型"
        align="center"
        key="categoryDictText"
        prop="categoryDictText"
        :show-overflow-tooltip="true"
      />

      <el-table-column
        label="测试用时（分钟）"
        align="center"
        key="duration"
        prop="duration"
      />
      <el-table-column
        label="测评时段"
        align="center"
        prop="createTime"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span>{{ scope.row.startDate }}</span>
          <span>—</span>
          <span>{{ scope.row.endDate }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="测评状态"
        align="center"
        key="measureStatusDictText"
        prop="measureStatusDictText"
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="reportClik(scope.row)"
            v-hasPermi="['system:user:edit']"
            >报告</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-share"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:user:edit']"
            >测评</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 测评对话框 -->
    <el-dialog
      title="测评"
      :visible.sync="open"
      width="800px"
      append-to-body
      :close-on-click-modal="false"
    >
      <div class="testCss" v-for="(item, index) in testList" :key="index">
        <div>{{ index + 1 }}.{{ item.title }}</div>
        <div class="answer">
          <div
            class="answerTset"
            v-for="(items, indexs) in item.selectionItems"
            :key="indexs"
          >
            <el-radio v-model="item.radio" :label="items.selectionItemId">
              {{ items.optionText }}
            </el-radio>
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">提 交</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 用户导入对话框 -->
    <!-- <el-dialog
      title="报告"
      :visible.sync="upload.open"
      width="400px"
      append-to-body
    >
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog> -->
  </div>
</template>

<script>
import {
  formcfgList, //量表列表
  formSetting, //测评详情
  scaleDtail, //试题详情
} from "@/api/itemBank/index";

export default {
  name: "User",
  dicts: [
    "sys_normal_disable",
    "sys_user_sex",
    "suitable_object",
    "measure_status",
  ],
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      //禁止输入
      displays: false,
      // 总条数
      total: 0,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 搜素日期范围
      dateRange1: [],
      // 量表选项
      scaleList: [],
      //   试题列表
      testList: [],
      // 表单参数
      form: { classIds: [], schoolIds: null, studentIds: [] },

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
    };
  },
  watch: {},
  created() {
    this.getList();
  },
  methods: {
    /** 查询测评列表 */
    getList() {
           this.loading = false;
           return
      this.loading = true;
      this.queryParams.measureType = "2";
      formSetting(this.queryParams).then((response) => {
        // this.scaleList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.dateRange = [];

      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      (this.queryParams.startDate = this.dateRange1[0]),
        (this.queryParams.endDate = this.dateRange1[1]),
        (this.queryParams.pageNum = 1);
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      // this.dateRange = [];
      this.dateRange1 = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.open = true;
      scaleDtail(row.formId).then((response) => {
        response.data.elements.forEach((val) => {
          val.radio = "";
        });
        this.testList = response.data.elements;
      
      });
    },

    /** 提交按钮 */
    submitForm: function () {
          console.log("量表信息3", this.testList);
    },

    //上传模型
    reportClik() {
      //   this.upload.title = "测评报告";
      //   this.upload.open = true;
    },

    // 提交上传文件
    submitFileForm() {},
  },
};
</script>
<style scoped lang="scss">
.testCss {
  width: 100%;
  //   height: 60px;
  padding: 10px 10px;
  .answer {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
  }
  .answerTset {
    height: 25px;
    line-height: 25px;
    padding: 10px 10px;
  }
}
</style>
